package com.dirven.game.sprite;

import com.dirven.game.DirVenGame;
import com.dirven.game.Grid;
import com.dirven.game.Path;

public class RedEnemy extends GridSprite {

	Path path;
	
	public RedEnemy(int x, int y) {
		super(x, y, GridSprite.TYPE_NPC, "cycle", "red.png");
		
		// Set the direction to west.
		setDirection(DIRECTION_WEST);
		
		path = new Path(this, false);
		path.addWaypoint(Grid.genRandomCoord());
		path.addWaypoint(Grid.genRandomCoord());
		path.addWaypoint(Grid.genRandomCoord());
		
	}

	@Override
	public void movementAI() {
		//TODO: FINISH THE AI
		// Do AI stuff...
		
		// If not finished movign along path...
		if(path != null && path.isFinishedMovingAlongPath() == false) {
			// Keep on moving along the path.
			path.moveAlongPath();
		} else {
			path = null;
		}
		
		int difficultySetting = DirVenGame.getDifficulty();
		switch(difficultySetting) {
		
			case DirVenGame.DIFFICULTY_EASY:
				// DO EASY AI
			break;
			
			case DirVenGame.DIFFICULTY_AVERAGE:
				// DO AVERAGE AI
			break;
			
			case DirVenGame.DIFFICULTY_HARD:
				// DO HARD AI
			break;
			
			case DirVenGame.DIFFICULTY_HARDCORE:
				// DO HARDCORE AI
			break;
		
		}
		
		// Prevent head from going backwards and killing itself
		if(nextCoordinateNotHead(direction) == false) {
			if(direction == DIRECTION_NORTH) {
				setDirection(DIRECTION_SOUTH);
			} else if(direction == DIRECTION_SOUTH) {
				setDirection(DIRECTION_NORTH);
			} else if(direction == DIRECTION_EAST) {
				setDirection(DIRECTION_WEST);
			} else if(direction == DIRECTION_WEST) {
				setDirection(DIRECTION_EAST);
			}
		}
		
		// Move the sprite and append the new head cell.
		
		//if(getChainLength() >= 5) {
		//	// Move 1 grid unit
		//	move(false);
		//} else {
			move(true);
		//}
	}

	@Override
	public void onCollide() {
		setMovementDisabled(true);
		
		//onKilled();
	}

	@Override
	public void onKilled() {
		setVisible(false);
		setDead(true);
	}

}
